package test;

import java.util.Scanner;

public class ZiGuang1 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int number = in.nextInt();
        int res = calSum(number);
        System.out.println(res);

    }
    private static int calSum(int number) {
        if (number <= 100){
            return 0;
        }
        int count = 0;
        for (int i = 100; i < number; i++) {
            if (isLegal(i)){
                count += i;
            }
        }
        return count;
    }

    private static boolean isLegal(int num) {
        String strNum = String.valueOf(num);
        if (strNum.charAt(0) != '3' && strNum.charAt(1) != '5' && strNum.charAt(2) != '7'){
            return true;
        }
        return false;
    }
    private static boolean isLegal1(int num) {
        String strNum = String.valueOf(num);
        int len = strNum.length();
        if (strNum.charAt(len - 1) != '7' && strNum.charAt(len - 2) != '5' && strNum.charAt(len - 3) != '3'){
            return true;
        }
        return false;
    }
}
